/*
 * @Date: 2024-04-22 10:45:46
 * @LastEditors: lyx
 * @LastEditTime: 2024-04-22 10:47:22
 * @FilePath: \taro-template3\src\packageA\components\ChatRcTable\index.tsx
 * @Description: 
 */
import React, { useEffect, useState } from 'react'
import RcTable, { TableProps } from 'rc-table'
import { ColumnsType } from 'rc-table/es/interface'
import { transColumns } from './util'
import type { ChatTable } from './type'
import './index.less'

const prefixCls = 'supgpt-app-table'

export type AppTableProps = Omit<TableProps<any>, 'columns'> & {
  columns: ChatTable.ColumnsType
}

const Table: React.FC<AppTableProps> = (props) => {
  // Component State
  const [resColumns, setResColumns] = useState<ColumnsType<any>>([])
  // Component Effect
  useEffect(() => {
    if (props.columns) {
      setResColumns(transColumns(props.columns))
    }
  }, [props.columns])

  return (
    <RcTable scroll={{
      x: true,
      y: '100%'
    }} prefixCls={props.prefixCls || prefixCls} columns={resColumns} data={props.data}></RcTable >
  )
}

export default Table
